﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.ViewModels;

namespace Chefbook.UserActions
{
    /// <summary>
    /// An Action to move a category to another parent
    /// </summary>
    public class MoveCategoryAction : UserActionBase
    {
        private CategoryViewModel categoryToMove, newParent, oldParent;

        /// <summary>
        /// Creates a new action to move a category from one parent to another
        /// </summary>
        /// <param name="categoryToMove">The category to move</param>
        /// <param name="newParent">The new parent</param>
        public MoveCategoryAction(CategoryViewModel categoryToMove, CategoryViewModel newParent)
            : base()
        {
            this.categoryToMove = categoryToMove;
            this.newParent = newParent;
            this.oldParent = categoryToMove.Parent;
        }

        /// <summary>
        /// Moves the category to the new parent
        /// </summary>
        public override void DoAction()
        {
            base.DoAction();
            categoryToMove.Parent = newParent;
        }

        /// <summary>
        /// Moves the category back to the old parent
        /// </summary>
        public override void UndoAction()
        {
            base.UndoAction();
            categoryToMove.Parent = oldParent;
        }

        /// <summary>
        /// Returns a user-friendly string describing the action
        /// </summary>
        /// <returns>A user-friendly string describing the action</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Move Category '{0}' from '{1}' to '{2}'", categoryToMove, oldParent, newParent);
        }
    }
}
